package main

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
)

type User struct {
	Name string
	Age  int
	City string
}

func getPhones(str []string) []string {

	for i := 0; i < len(str); i++ {
		str[i] = "+" + str[i]
	}
	return str
}

func main() {

	s := []string{
		"111111",
		"222222222",
	}
	s = getPhones(s)
	fmt.Println(s)

	return
	// 创建一个 Redis 客户端实例
	client := redis.NewClient(&redis.Options{
		Addr:     "198.200.54.86:8002", // Redis 服务器地址
		Password: "",                   // 密码
		DB:       5,                    // 数据库索引
	})

	key := "src_list_1693443837097"
	members := []string{
		"17739394562",
	}
	if err := client.SRem(context.Background(), key, members).Err(); err != nil {
		fmt.Println(err)
	}
	return
	// 创建一个上下文，用于取消操作
	ctx := context.Background()

	// 设置一个 Redis 哈希表
	userID := "user:123"
	//userFields := map[string]interface{}{
	//	"name": "Alice",
	//	"age":  30,
	//	"city": "New York",
	//}

	userFields := struct {
		Name string `json:"name" redis:"name"`
		Age  int    `json:"age" redis:"age"`
		City string `json:"city" redis:"city"`
	}{
		Name: "Alice",
		Age:  30,
		City: "New York",
	}
	err := client.HMSet(ctx, userID, userFields).Err()
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	fmt.Println("User data saved successfully")

	// 获取 Redis 哈希表的字段值
	userData, err := client.HGetAll(ctx, userID).Result()
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	fmt.Println("User Data:", userData)

	// 将哈希表字段值解析为结构体
	var user User
	err = client.HGetAll(ctx, userID).Scan(&user)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	fmt.Println("User Name:", user.Name)
	fmt.Println("User Age:", user.Age)
	fmt.Println("User City:", user.City)
}
